/**
 * Copyright  2025, Hai Yue Xing He Technology Co., Ltd
 * 
 * @author        ZHAO LIMIN
 * @version       1.0.1
 * @since         2025-04
 * HResource.ts              用于管理精灵资源的类，及各个资源的加载
 *                           所有场景的通用资源在启动游戏的时候，
 *                           统一加载到内存中，方便后续使用
 *                           主要是加载场景资源，及场景中的资源，   
 */

import { AnimationClip, AudioClip, SpriteFrame } from "cc";
import { Rectangle } from "../hyxh/core/Rectangle";

export enum HResourceType {
   NONE = 0,
   IMAGE = 1,
   AUDIO = 2,
   MEDIA = 3,
   ANIMATION = 4,
   ANIMATIONCONTROL = 5,
}

/**
 * image 用于spriteFrame 显示框架
 */
export class FrameFrame {
    public rect: Rectangle;
    public sourceSize: number[];   // 原始大小
    public size: number[];         // 在系统显示大小
}
/**
 * 资源配置信息，
 */
export class HResource { 
    // 资源ID
    public rid: number;
    // 资源类型，如：图片，音频，视频等
    public model: HResourceType = HResourceType.NONE;
    // 资源名称
    public name: string;
    // 资源路径
    public url: string;
    // 资源边界
    public frames: FrameFrame; 
    constructor(rid: number, name: string, url: string) {
        this.rid = rid;
        this.name = name;
        this.url = url; 
    }
}
/**
 * 精灵用于SpriteFrame
 */
export class HImageResource extends HResource {
   /* 初始的Sprite */
   public spriteFrame: SpriteFrame;
   constructor(rid: number, name: string, url: string) {
      super(rid, name, url);
      this.model = HResourceType.IMAGE;
   }
}

/**
 * 音频
 */
export class HAudioResource extends HResource {
    /* 初始的Sprite */
    public audioClip: AudioClip;
    constructor(rid: number, name: string, url: string) {
       super(rid, name, url);
       this.model = HResourceType.AUDIO;
    }
 }

/**
 * 动画
 */
export class HAnimationResource extends HResource {
    /* 初始的Sprite */
    public animationClip: AnimationClip;
    constructor(rid: number, name: string, url: string) {
       super(rid, name, url);
       this.model = HResourceType.ANIMATION;
    }
}
/**
 * {
 *      "index": 0,
 *      "frame":9001025,
 *      "translation":[0.00,0.00,0.00],
 *      "rotation":[0.00,0.00,0.00],
 *      "scale":[1.00,1.00,1.00]
 * }
 */
export class HAnimationFrame {
    public index: number;               // 次序
    public frame: number;               // rid
    public translation: number[];       // 位置转换  
    public rotation: number[];          // 旋转
    public scale: number[];             // 缩放
}

/**
 * 动画控制，动态生成AnimationClip, 并调用SpriteFrame 和配置
 * 生成动画，用于动态生成动画
 * 
 * {
            "rid": 80110002,
            "name": "animation_losted110001",
            "model": 94,
            "seepd": 1,
            "sample":10,
            "duration": 2,
            "animframes": [                
            ],
            "wrapMode": "default"
        }
 */
export class HAnimationControlResource extends HResource {
    /* 初始的Sprite */   
    public speed: number;                       // 播放速度
    public sample: number;                      // 采样
    public duration: number;                    // 持续时间
    public animframes: HAnimationFrame[];       // 动画帧
    public wrapMode: number;                    // 循环模式               

    constructor(rid: number, name: string, url: string) {
       super(rid, name, url);
       this.model = HResourceType.ANIMATIONCONTROL;
    }
}